/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-16 14:59:04
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-16 16:35:55
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/controller/common_controller.dart';
import 'package:get/get.dart';

import '../../../constants.dart';

class MenuGrid extends StatelessWidget {
  const MenuGrid({Key key, this.currentIndex, this.onChange}) : super(key: key);
  final int currentIndex;
  final ValueChanged<int> onChange;

  @override
  Widget build(BuildContext context) => GetBuilder<CommonController>(
        builder: (_controller) => Padding(
          padding: const EdgeInsets.only(
            left: 8,
            right: 8,
            top: 8,
            bottom: 60,
          ),
          child: GridView.builder(
            physics: BouncingScrollPhysics(),
            padding: EdgeInsets.all(5),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              crossAxisSpacing: 20,
              mainAxisSpacing: 15,
              childAspectRatio: 2,
            ),
            itemCount: _controller.floors.length,
            itemBuilder: (context, index) => InkWell(
              onTap: () => onChange(index),
              child: Container(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: index == currentIndex
                      ? Colors.white
                      : Colors.grey.withOpacity(0.2),
                  borderRadius: BorderRadius.circular(defaultRadius),
                ),
                child: Text(
                  _controller.floors[index].name,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    color: index == currentIndex ? primaryColor : Colors.white,
                  ),
                ),
              ),
            ),
          ),
        ),
      );
}
